/*
 * Copyright (c) 2017-2020, Lindenis Tech. Ltd.
 * All rights reserved.
 *
 * File:
 *
 * Description:
 *
 * Author:
 *      xiaoshujun@lindeni.com
 *
 * Create Date:
 *      2020/10/14
 *
 * History:
 *
 */

#ifndef __AUDIO_DEVICE_WRAPPER_H__
#define __AUDIO_DEVICE_WRAPPER_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "lindcomponent.h"

#define DEFAULT_OUT_SAMPLING_RATE   AUDIO_SAMPLE_RATE_44K
#define DEFAULT_OUT_CHANNELS        AUDIO_CHANNEL_STERO
#define DEFAULT_OUT_BITS            AUDIO_BITS_16

/**
 * Define a function pointer.
 * adev will create a thread in calling adev_in/out_open().
 * The thread will request the caller to write pcm buffer in param 'data' with size 'size'.
 * Then adev will write to/read from the alsa driver.
 *
 * @param
 *    user: who will response the request of writing pcm data.
 *    data: a buffer malloc in av_wrapper.
 *    len: the size of param 'data'.
 * @return
 *    >0 success, other error
 */
typedef int (*adev_pcm_cb)(void * user, void * data, int size);

typedef struct _adev_config_t
{
    audio_device_e      device;

    unsigned int        channels;
    unsigned int        rate;
    unsigned int        bits;

    unsigned int        period_size;
    unsigned int        period_count;

    adev_pcm_cb         pcm_cb;
    void *              user;
} adev_config_t;

_handle_t adev_in_create();
void adev_in_destroy(_handle_t h_adev);
int adev_in_open(_handle_t h_adev, adev_config_t * p_config);
int adev_in_close(_handle_t h_adev);
int adev_in_read(_handle_t h_adev, uint8_t * data, int size);

_handle_t adev_out_create();
void adev_out_destroy(_handle_t h_adev);
int adev_out_open(_handle_t h_adev, adev_config_t * p_config);
int adev_out_close(_handle_t h_adev);
int adev_out_write(_handle_t h_adev, uint8_t * data, int size);

#ifdef __cplusplus
}
#endif

#endif  // __AUDIO_DEVICE_WRAPPER_H__

